package com.jack.charging.order.mqtt;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Jack
 * @date 2025/2/12 09:33
 * @see
 * @since
 */
@Slf4j
@Component
public class MqttProducer {
    @Autowired
    private MqttClient mqttClient;

    public boolean send(String topic, String message)
    {
        try
        {
            mqttClient.publish(topic, message.getBytes(), 0, false);
            return true;
        }
        catch (Exception e)
        {
            log.error("send message error", e);
            return false;
        }
    }

}
